// @Author EthanScriptOn
// @Desc
package identity

import (
	"errors"
	"gitee.com/fatzeng/srf_switch_basic_components/util"
	"reflect"
)

// StructNameObjectId  Generate identity information related to the structure name
type StructNameObjectId struct {
	structTyp  reflect.Type
	identifier interface{}
}

func (s *StructNameObjectId) GenerateUniqueIdentifier() (interface{}, error) {
	if s.identifier != nil {
		return s.identifier, nil
	}
	if s.structTyp == nil {
		return nil, errors.New("struct type is nil")
	}
	structName := s.structTyp.Name()
	s.identifier = util.CamelToSnake(structName)
	return s.identifier, nil
}

func GenerateStructNameObjectId(typ reflect.Type) *StructNameObjectId {
	return &StructNameObjectId{structTyp: typ}
}
